package com.wootion.cims.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.wootion.cims.module.communityresidence.household.dto.HouseholdDto;
import com.wootion.cims.module.communityresidence.occupancy.dto.OccupancyDto;
import com.wootion.cims.module.communityresidence.residencelist.dto.ResidenceDto;
import com.wootion.cims.module.communityresidence.residencelist.excel.ResidenceExcel;
import com.wootion.cims.module.communityresidence.residencelist.model.Residence;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * @Author: LanQiang
 * @Date: 2022/12/08/16:05
 * @Description: 作用xxx
 */
@Mapper
public interface ResidenceDao extends BaseMapper<Residence> {
    /**
     * 查询对应的社区id(去重)
     */
    List<String> communityIds(@Param("ids") List<String> ids, @Param("classes") String classes, @Param("category") String category);

    /**
     * 根据社区权限，查询住宅信息
     */
    PageDTO<ResidenceDto> pageResidenceList(@Param("page") PageDTO<ResidenceDto> pageDTO,
                                            @Param("ids") List<String> ids,
                                            @Param("keyWord") String keyWord,
                                            @Param("residenceClasses") String residenceClasses,
                                            @Param("residenceCategory") String residenceCategory,
                                            @Param("communityId") String communityId,
                                            @Param("plotId") String plotId,
                                            @Param("detailedAddress") String detailedAddress,
                                            @Param("houseNumber") String houseNumber);

    /**
     * 批量删除住宅列表，软删除
     * @param ids
     * @return
     */
    int updateEnabled(@Param("ids") List<String> ids);

    /**
     * 双击查看社区列表中的详情信息
     *
     * @param id
     * @return
     */
    ResidenceDto findByCommunityId(@Param("id") String id);


    /**
     * 根据条件导出住宅列表excel
     * @param ids
     * @param commnityIds
     * @param keyWord
     * @param residenceClasses
     * @param residenceCategory
     * @param communityId
     * @param plotId
     * @param detailedAddress
     * @param houseNumber
     * @return
     */
    List<ResidenceExcel> findConditionExcel(@Param("ids") List<String> ids,
                                            @Param("commnityIds") List<String> commnityIds,
                                            @Param("keyWord") String keyWord,
                                            @Param("residenceClasses") String residenceClasses,
                                            @Param("residenceCategory") String residenceCategory,
                                            @Param("communityId") String communityId,
                                            @Param("plotId") String plotId,
                                            @Param("detailedAddress") String detailedAddress,
                                            @Param("houseNumber") String houseNumber);

    /**
     * 根据查询满足条件的入住人数人员信息
     * @param min
     * @param max
     * @return
     */
    List<Map<String,Object>> countNumberPersonAbode(@Param("min") Integer min,@Param("max") Integer max);
    /**
     * 根据查询满足条件的户籍人数人员信息
     * @param min
     * @param max
     * @return
     */
    List<Map<String,Object>> countNumberPersonPlace(@Param("min") Integer min,@Param("max") Integer max);

    /**
     * SELECT
     * 	r.id,p.abode_id
     * FROM
     * 	residence r left join person p on r.id = p.abode_id AND p.enabled = 1 where  r.enabled = 1
     * 	group by r.id
     * @return
     */
    List<Map<String,Object>> countAbodeIdIsNull();

    /**
     *SELECT
     * 	r.id,
     * 	p.place_id
     * FROM
     * 	residence r
     * 	LEFT JOIN person p ON r.id = p.place_id
     * 	AND p.enabled = 1
     * WHERE
     * 	r.enabled = 1
     * GROUP BY
     * 	r.id
     * @return
     */
    List<Map<String,Object>> countPlaceIdIsNull();
    /**
     * @param pageDTO
     * @param commnityIds
     * @param ids
     * @param keyWord
     * @param residenceClasses
     * @param residenceCategory
     * @param communityId
     * @param plotId
     * @param detailedAddress
     * @param houseNumber
     * @return
     */
    PageDTO<OccupancyDto> findList(@Param("page") PageDTO<OccupancyDto> pageDTO,
                                @Param("commnityIds") List<String> commnityIds,
                                @Param("ids")List<String> ids, 
                                @Param("keyWord")String keyWord,
                                @Param("residenceClasses")String residenceClasses,
                                @Param("residenceCategory")String residenceCategory,
                                @Param("communityId")String communityId,
                                @Param("plotId")String plotId,
                                @Param("detailedAddress")String detailedAddress,
                                @Param("houseNumber")String houseNumber);

    /**
     * 修改住宅备注
     * @param id
     * @param remark
     * @return
     */
    void updateByIdRemark(@Param("id") String id,@Param("remark") String remark);

    /**
     * 修改入住人员备注
     * @param id
     * @param checkRemark
     */
    void updateCheckRemark(@Param("id") String id,@Param("checkRemark") String checkRemark);
    /**
     * 修改户籍人员备注
     * @param id
     * @param houseRemark
     */
    void updateHouseRemark(@Param("id") String id,@Param("houseRemark") String houseRemark);
    /**
     * @param pageDTO
     * @param commnityIds
     * @param ids
     * @param keyWord
     * @param residenceClasses
     * @param residenceCategory
     * @param communityId
     * @param plotId
     * @param detailedAddress
     * @param houseNumber
     * @return
     */
    PageDTO<HouseholdDto> findListHouse(@Param("page") PageDTO<HouseholdDto> pageDTO,
                                        @Param("commnityIds") List<String> commnityIds,
                                        @Param("ids")List<String> ids,
                                        @Param("keyWord")String keyWord,
                                        @Param("residenceClasses")String residenceClasses,
                                        @Param("residenceCategory")String residenceCategory,
                                        @Param("communityId")String communityId,
                                        @Param("plotId")String plotId,
                                        @Param("detailedAddress")String detailedAddress,
                                        @Param("houseNumber")String houseNumber);

    /**
     * 根据住宅地址中楼号名称和单元名和小区id，使用json查询
     */
    Residence findByBuildingAndUnit(@Param("id") String id,
                                    @Param("buildingId") String buildingId,
                                    @Param("unitId") String unitId);
}
